﻿using System;
using System.Data;
using System.Web.UI.WebControls;
using BLL;
using Utils;
namespace UI.ModSalesman
{
    public partial class ChangeList : System.Web.UI.Page
    {
        SalesmanBiz salesmanBiz = new SalesmanBiz();    
       
        protected void Page_Load(object sender, EventArgs e)
        {
            string saleManID = "0";
            if (Request.Params["SaleManID"] != null) saleManID = Request.Params["SaleManID"].ToString().Trim();
            //if (Request.Params["BTime"] != null) bTm = Request.Params["BTime"].ToString().Trim();
            //if (Request.Params["ETime"] != null) eTm = Request.Params["ETime"].ToString().Trim();
            if (!IsPostBack)
            {
                btnAdd.Attributes.Add("onclick", "javascript:ShowLink('ChangeAdd.aspx',800,600);");
                // JSUtility.AddReset(btnClear);
                if (saleManID != "0")
                {


                    DataTable dt = salesmanBiz.GetChangeLists(saleManID);
                    gvList.DataSource = dt;
                    gvList.DataBind();
                    lbAmount.Text = dt.Rows.Count.ToString();
                }
            }
        }

        protected void btnEmSearch_Click(object sender, EventArgs e)
        {
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            if (string.IsNullOrEmpty(serWord) && string.IsNullOrEmpty(bTime))
            {
                bTime = System.DateTime.Now.AddMonths(-2).ToString("yyyy-MM-dd");
                txtBtime.Text = bTime;
                txtEtime.Text = System.DateTime.Now.ToString("yyyy-MM-dd");
            }

            if (StringUtility.GetDiffDays(bTime, eTime) > XmlUtility.GetNumFormConfig("daysOfSearch"))
            {
                JSUtility.Alert(this, "查询日期间隔不能大于" + XmlUtility.GetNumFormConfig("daysOfSearch") + "天！");
                return;
            }
            DataTable dt = salesmanBiz.GetChangeLists(serWord, bTime, eTime);
            gvList.DataSource = dt;
            gvList.DataBind();
            lbAmount.Text = dt.Rows.Count.ToString();
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            txtBtime.Text = "";
            txtEtime.Text = "";
            txtSerWord.Text = "";
        }

        protected void btnPrint_Click(object sender, EventArgs e)
        {
            ToolUtility.Printer("促销员变动表", gvList);
        }


        protected void btnExcel_Click(object sender, EventArgs e)
        {
            //ExcelUtility.GridViewToExcel(gvList, "SalesChange.xls");
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            ExcelUtility.ExportDsToXls(this, salesmanBiz.GetChangeLists(serWord, bTime, eTime), "SalesChange.xls");

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {

        }

        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F3F8F8'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            }
        }
    }
}